import { updateById, deleteById } from "@/api/feedbackApi";

export default {
  data() {
    return {
      // 分页工具
      page: 1,
      pageSize: 10,
      // 弹出框
      centerDialogVisible: false,
      feedbackFormTable: {
        id: "",
        handleStatus: "",
        ficationStatus: "",
      },
    };
  },
  methods: {
    // 分页查询
    FeedbackGO() {
      // const nickname = this.searchNickname;
      // const status = this.searchStatus;
      // const page = this.Page;
      // const pageSize = this.pageSize;
      this.$store.dispatch("getFeedback", {
        page: this.page,
        pageSize: this.pageSize,
      });
    },
    // 分页工具
    handleSizeChange(val) {
      this.pageSize = val;
      this.FeedbackGO();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.FeedbackGO();
    },
    // 弹窗取消操作
    updateUserError() {
      this.FeedbackGO();
      this.$message.warning("取消操作");
      this.centerDialogVisible = false;
    },
    // 弹窗
    feedbackFormTableUpdate(row) {
      if (row.handleStatus === 2 && row.ficationStatus === 1) {
        this.$message.error("该反馈已被处理，无法修改");
        return false;
      }
      this.centerDialogVisible = true;
      this.feedbackFormTable.id = row.id;
      this.feedbackFormTable.handleStatus = row.handleStatus;
      this.feedbackFormTable.ficationStatus = row.ficationStatus;
    },
    // 修改确定按钮
    feedbackFormStatusUpdate() {
      console.log(this.feedbackFormTable);
      updateById(this.feedbackFormTable).then((resp) => {
        if (resp.data.msg != "success") {
          this.$message.error("修改失败");
        }
        this.$message.success("修改成功");
        this.FeedbackGO();
        this.centerDialogVisible = false;
      });
    },
    // 删除方法
    feedbackFormTableDelete(row) {
      switch (row.handleStatus) {
        case 0:
          this.$message.warning("未处理的反馈不能删除");
          return false;
        case 1:
          this.$message.warning("处理中的反馈不能删除");
          return false;
      }
      if (row.ficationStatus === 0) {
        this.$message.warning("未发送通知的反馈不能删除");
        return false;
      }
      deleteById(row.id).then((resp) => {
        if (resp.data.msg != "success") {
          this.$message.error("删除失败");
        }
        this.$message.success("删除成功");
        this.FeedbackGO();
      });
    },
  },
  mounted() {
    this.FeedbackGO();
  },
};
